﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Framework.Manager;
using Framework.Singleton;


namespace Framework.Util
{
    public class UIUtil : Singleton<UIUtil>
    {
        private UIUtil() { }

        public void SetImageSprite(Image pIamge, string pSpriteName, bool pIsNativeSize = true)
        {
            Texture texture = ManagerCollection.ResourceManager.GetTexture(pSpriteName);
            if (texture)
            {
                pIamge.sprite = Sprite.Create(texture as Texture2D, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
                if (pIsNativeSize)
                    pIamge.SetNativeSize();
            }
            else
            {
                Debug.LogWarning(string.Format("Set image sprite failed. Texture {0} is not exist.", pSpriteName));
            }
        }
    }
}